package com.woniu.controller;


import com.woniu.entity.Floors;
import com.woniu.service.IFloorsService;
import com.woniu.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Gapper
 * @since 2021-03-29
 */
//楼层信息表
@RestController
public class FloorsController {
    @Autowired
    private IFloorsService floorsService;

    /**
     新增
     */

    @PostMapping("/floors/save")
    private ResultVO sava(@RequestBody Floors floors){
        boolean falg=false;
        try {
            falg = floorsService.save(floors);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return (falg ? ResultVO.success() : ResultVO.failure());

    }

    /**
     删除
     */
    @PostMapping("/floors/deleteById")
    private ResultVO deleteById(@RequestBody String fid){
        int rows=0;
        try {
            rows = floorsService.deleteById(fid);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return (rows > 0 ? ResultVO.success() : ResultVO.failure());

    }

    /**
     修改
     */
    @PostMapping("/floors/updateById")
    private ResultVO updateById(@RequestBody Floors floors){
        boolean falg = false;
        try {
            falg=floorsService.updateById(floors);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return (falg ? ResultVO.success() : ResultVO.failure());

    }

    /**
     查询全部
     */
    @PostMapping("/floors/findAll")
    private ResultVO findAll(){

        List<Floors> list = null;
        try {
            list = floorsService.findAll();
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return ResultVO.success(list);
    }

    /**
     查一个
     * */
    @PostMapping("/floors/findById")
    private ResultVO findById(@RequestBody String fid){
        List<Floors> list=null;
        try {
            list = floorsService.findById(fid);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return ResultVO.success(list);

    }

    /**
     根据单元号，查询楼层
     */
    @PostMapping("/floors/findByUid")
    private ResultVO findByUid(@RequestBody String uid){
        List<Floors> list=null;
        try {
           list = floorsService.findByUid(uid);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return ResultVO.success(list);
    }

    /**
     查询所有去重
     */
    @PostMapping("/floors/find")
    private ResultVO find(){
        List<Floors> list=null;
        try {
            list = floorsService.find();
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return ResultVO.success(list);
    }

}

